<style>
    .center{
        text-align:center;
    }
    .table-action-area{
        float: right;
    }
    .demo-slider{
        width:200px;
        top: 15px;
    }
    .layui-form-label-two {
        width: 170px;
    }
    .layui-input-block-two {
        margin-left: 200px;
    }
    .layui-width{
        width: 150px;
    }
</style>
<div class="layui-fluid layui-anim website-anim" id="website-configure" lay-title="评审规则管理">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full" id="table-view">
                    <form class="layui-form layui-table-form" lay-filter="configure-update-form">
                        <div class="layui-form-item ">
                            <div class="layui-row">
                                <div class="layui-col-md6">
                                    <label class="layui-form-label layui-form-label-two website-form-item-require">业务类型：</label>
                                    <div class="layui-input-block layui-input-block-two">
                                        <input type="hidden" id="configureId" name="configureId" data-th-value="${configure.configureId}">
                                        <input type="radio" name="businessTypeCode" value="0" title="有意向申请流程" checked="">
                                        <input type="radio" name="businessTypeCode" value="1" title="无意向申请流程">
                                    </div>
                                </div>
                                <div class="layui-col-md6">
                                    <label class="layui-form-label layui-form-label-two website-form-item-require">分配比例优化值(%)：</label>
                                    <div id="slideTest" class="layui-input-block layui-input-block-two demo-slider"></div>
                                    <input type="hidden" name="proportion" lay-verify="required" id="proportion">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-row">
                                <div class="layui-col-md6">
                                    <label class="layui-form-label layui-form-label-two website-form-item-require">工作量：</label>
                                    <div class="layui-input-block layui-input-block-two layui-width">
                                        <input type="text" name="workload" lay-verify="required" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-col-md6">
                                    <label class="layui-form-label layui-form-label-two website-form-item-require">同单位专家可分配到同组：</label>
                                    <div class="layui-input-block layui-input-block-two">
                                        <input type="radio" name="isDistribution" value="1" title="是" checked="">
                                        <input type="radio" name="isDistribution" value="0" title="否">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-md6">
                                <label class="layui-form-label layui-form-label-two website-form-item-require">优先专家：</label>
                                <div class="layui-input-block layui-input-block-two">
                                    <input type="radio" name="expertLocationCode" value="0" title="京内专家" checked="">
                                    <input type="radio" name="expertLocationCode" value="1" title="京外专家">
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <label class="layui-form-label layui-form-label-two website-form-item-require">优先实务/理论专家：</label>
                                <div class="layui-input-block layui-input-block-two">
                                    <input type="radio" name="expertSpecialCode" value="0" title="实务专家" checked="">
                                    <input type="radio" name="expertSpecialCode" value="1" title="理论专家">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-col-md6">
                                <label class="layui-form-label layui-form-label-two website-form-item-require">专家数：</label>
                                <div class="layui-input-block layui-input-block-two layui-width">
                                    <input type="text" name="expertNum" lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <label class="layui-form-label layui-form-label-two website-form-item-require">填写课题级别：</label>
                                <div class="layui-input-block layui-input-block-two">
                                    <input type="radio" name="isTopicLev" value="1" title="是" checked="">
                                    <input type="radio" name="isTopicLev" value="0" title="否">
                                </div>
                            </div>
                        </div>
                        <div class="center">
                            <div class="layui-btn website-hide" id="query"/>
                            <button class="layui-btn" lay-submit="" lay-filter="configure-form-submit" id="submit">保存</button>
                        </div>
                    </form>
                    <div class="table-action-area">
                        <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action" id="configureDetailAdd">
                            新增列表
                        </div>
                    </div>
                    <div class="layui-row">
                        <table lay-filter="configureTableAdd" id="configureTableAdd"
                               lay-data="{id: 'configureTableAdd'}"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="topic-type">
    {{#
    var dict=layui.dict.getByCode(d.levelTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="position-type">
    {{#
    var dict=layui.dict.getByCode(d.positionTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="declaration-method">
    {{#
    var declarationMethod=(d.declarationMethodCode);
    }}
    {{#  if(declarationMethod=='0'){ }}
    <span>{{ '个人' }}</span>
    {{#  }else if(declarationMethod=='1') { }}
    <span>{{ '课题组' }}</span>
    {{# }else { }}
    <span>{{ '' }}</span>
    {{# } }}
</script>
<script type="text/html" id="configure-detail-option">
    {{# if(d.isPublish){}}
    <a lay-event="detail" shiro:hasPermission="configureQualification:list" class="website-green">详情</a>
    {{# } else { }}
    <a lay-event="detail" shiro:hasPermission="configureQualification:list" class="website-green">详情</a>
    <a lay-event="edit" shiro:hasPermission="configureQualification:update" class="website-blue">修改</a>
    <a lay-event="del" shiro:hasPermission="configureQualification:delete" class="website-red">删除</a>
    {{# } }}
</script>
<script type="text/html" id="configure-publish">
    <input type="checkbox" {{ d.isPublish ? 'checked' : '' }} value="{{d.configureQualificationId}}" lay-filter="publish_status" lay-skin="switch" lay-text="发布|取消"/>
</script>
<script data-th-inline="javascript">
    layui.use(['jquery', 'form', 'formSelects', 'table', 'website', 'validate','slider','dict'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            formSelects = layui.formSelects,
            slider = layui.slider,
            table = layui.table,
            dict = layui.dict,
            $view = $('#website-configure'),
            $configureDetailAdd = $view.find('#configureDetailAdd'),
            $searchForm = $view.find('form'),
            $query = $view.find('#query'),
            configure = [[${configure}]],
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo,
            validate = layui.validate;
        form.verify(validate);
        initConfigureFormValue();
        initTable();
        form.render();
        formSelects.render();
        slider.render({
            elem: '#slideTest'
            ,value: configure.proportion
            ,min: 0 //最小值
            ,max: 100 //最大值
           ,change: function(value){
              console.log(value) //动态获取滑块数值
             $("#proportion").val(value);
          }
        });
        form.on('submit(configure-form-submit)', function (data) {
              var dateSoure=data.field;

              website.post(ctx + 'configure/update',dateSoure, function () {
                  layer.closeAll();
                  website.alert.success('数据修改成功');
                  window.location.reload();
            });
            return false;
        });
        /**
         * 发布按钮的点击事件
         */
        form.on('switch(publish_status)', function (obj) {
            website.post(ctx + 'configureQualification/publish/' + this.value, {isPublish: obj.elem.checked}, function () {
                var pulishMessage='发布成功';
                if(!obj.elem.checked){
                    pulishMessage='取消发布成功';
                }
                website.alert.success(pulishMessage);
                $query.click();
                $query.click();
            });
        });
        table.on('tool(configureTableAdd)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                website.modal.view('查看信息', 'biz/configure/configureQualificationDetail/' + data.configureQualificationId, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });
            }
            if (layEvent === 'del') {
                website.modal.confirm('删除信息', '确定删除该信息？', function () {
                    deleteConfigureQualification(data.configureQualificationId);
                });
            }
            if (layEvent === 'edit') {
                website.modal.open('修改信息', 'biz/configure/configureQualificationUpdate/' + data.configureQualificationId, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    offset: '30px',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#configureQualification-update').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });
        table.on('sort(configureTableAdd)', function (obj) {
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'configureTableAdd',
                url: ctx + 'configureQualification/list',
                where: {
                    configureId: $('#configureId').val()
                },
                cols: [
                    [
                        {type: 'numbers', title: '序号'},
                        {templet: '#topic-type', title: '课题分类', minWidth: 100},
                        {templet: '#declaration-method', title: '申报方式', minWidth: 100},
                        {templet: '#position-type', title: '职务', minWidth: 100},
                        {field: 'maxAge', title: '最大年龄', minWidth: 100},
                        {field: 'minAge', title: '最小年龄', minWidth: 100},
                        {title: '发布状态', templet: '#configure-publish',minWidth: 100},
                        {title: '操作',align:'center', templet: '#configure-detail-option', minWidth: 200}
                    ]
                ]
            });
        }
        $configureDetailAdd.on('click', function () {
            //判断父类是否为空
          var configureId=$('#configureId').val();
            if(configureId==null||configureId===''){
                website.alert.error('请先保存配置信息，再新增');
                return false;
            }
            website.modal.open('新增配置', 'biz/configure/configureQualificationAdd/' + $('#configureId').val(), {
                btn: ['提交', '重置'],
                area: $(window).width() <= 750 ? '95%' : '50%',
                offset: '30px',
                yes: function (index, layero) {
                    $('#configureQualification-add').find('#submit').trigger('click');
                },
                btn2: function () {
                    $('#configureQualification-add').find('#reset').trigger('click');
                    return false;
                }
            });
        });
        function deleteConfigureQualification(configureQualificationId) {
            website.post(ctx + 'configureQualification/delete/' + configureQualificationId, null, function () {
                website.alert.success('删除成功');
                $query.click();
            });
        }
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            var createTime = params.time;
            if (createTime) {
                createTimeFrom = createTime.split(' - ')[0];
                createTimeTo = createTime.split(' - ')[1];
            }
            params.invalidate_ie_cache = new Date();
            params.createTimeFrom = createTimeFrom;
            params.createTimeTo = createTimeTo;
            return params;
        }
        function initConfigureFormValue() {
            form.val("configure-update-form", {
                "configureId": configure.configureId,
                "businessTypeCode": configure.businessTypeCode,
                "proportion": configure.proportion,
                "workload": configure.workload,
                "isDistribution": configure.isDistribution,
                "expertLocationCode": configure.expertLocationCode,
                "expertSpecialCode": configure.expertSpecialCode,
                "isTopicLev": configure.isTopicLev,
                "expertNum": configure.expertNum
            });
        }

    })
</script>